package com.jnu.keepaccounts.manage;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.Toast;

import com.google.android.material.tabs.TabLayout;
import com.jnu.keepaccounts.R;
import com.jnu.keepaccounts.data.XuanKa;
import com.jnu.keepaccounts.record.Tab;

import java.util.ArrayList;

public class Manage extends AppCompatActivity {
    private TabLayout tabLayout;
    private ViewPager viewPager;
    private ArrayList<XuanKa> yXuanKas;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_manage);

        Intent intent = getIntent();
        this.yXuanKas = intent.getExtras().getParcelableArrayList("xuanKas");

        Button button = findViewById(R.id.delete_or_add);
        button.setOnClickListener(v -> {
            Toast.makeText(getApplicationContext(),"dddd",Toast.LENGTH_SHORT).show();
        });
        tabLayout = findViewById(R.id.tab);
        viewPager = findViewById(R.id.view_pager_tab_manage);

        ImageButton back = findViewById(R.id.back);
        back.setOnClickListener(v -> {
            finish();
        });
        ActionBar actionBar = getSupportActionBar();
        if(actionBar!=null){
            actionBar.hide();
        }

        ArrayList<String> arrayList = new ArrayList<>();

        arrayList.add("已启用");
        arrayList.add("未启用");

        prepareViewPager(viewPager,arrayList);

        tabLayout.setupWithViewPager(viewPager);
    }
    private void prepareViewPager(ViewPager viewPager, ArrayList<String> arrayList){
        Tab.MainAdapter adapter = new Tab.MainAdapter(getSupportFragmentManager());

        YFragment yFragment = new YFragment();
        NFragment nFragment = new NFragment();

        Bundle bundle = new Bundle();

        bundle.putString("title",arrayList.get(0));

        bundle.putParcelableArrayList("xuanKas", yXuanKas);

        yFragment.setArguments(bundle);

        adapter.addFragment(yFragment,arrayList.get(0));

        Bundle bundle1 = new Bundle();

        bundle1.putString("title",arrayList.get(1));

        nFragment.setArguments(bundle1);

        adapter.addFragment(nFragment,arrayList.get(1));

        viewPager.setAdapter(adapter);
    }
}